package com.zhj.algorithm.sort;

/**
 * @PackageName:com.zhj.structure.utils
 * @ClassName:MyQueue
 * @auter: 朱慧杰
 * @date:2020/8/8 0008 14:48
 **/
public class MyQueue {

    // 队列的底层我们用数组存储
    private int[] elements;

    public MyQueue() {
        elements = new int[0];
    }

    // 入队
    public void add(int element) {
        int[] newArr = new int[elements.length+1];
        for (int i = 0; i < elements.length; i++) {
            newArr[i] = elements[i];
        }
        newArr[elements.length] = element;
        elements = newArr;
    }

    // 出队
    public int poll() {
        if (elements.length == 0) {
            throw new RuntimeException("队列中没有元素！！！");
        }
        int element = elements[0];
        int[] newArr = new int[elements.length-1];
        for (int i = 0; i < elements.length-1; i++) {
            newArr[i] = elements[i+1];
        }
        elements = newArr;
        return element;
    }

    // 判断栈是否为空
    public boolean isEmpty() {
        return elements.length==0;
    }


}
